/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.date.DateUtil
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.Button
 *  javafx.scene.control.ChoiceBox
 *  javafx.scene.control.DatePicker
 *  javafx.scene.control.ScrollPane
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.TextField
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.VBox
 *  javafx.util.Callback
 *  javafx.util.StringConverter
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.rechargecard;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.CardLoseOrChangeQueryUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.CommonUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.index.IndexController;
import com.gys.data.example.GetUserOutData;
import com.gys.data.rechargecard.GetCardLoseOrChangeInData;
import com.gys.data.rechargecard.GetCardLoseOrChangeOutData;
import de.felixroske.jfxsupport.FXMLController;
import java.beans.ConstructorProperties;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class CardLoseOrChangeQueryController
extends BaseController
implements Initializable {
    @FXML
    private ScrollPane scrollPane;
    @FXML
    private VBox vBox;
    @FXML
    private Button sureBtn;
    @FXML
    private TextField oldCardNumQuery;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> date;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> shop;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> cardName;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> sex;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> index;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> oldCardId;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> newCardId;
    @FXML
    private TextField newCardNumQuery;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> voucherId;
    @FXML
    private TableView<GetCardLoseOrChangeOutData> tableView;
    @FXML
    private TextField nameQuery;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> time;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> user;
    @FXML
    private TextField phoneQuery;
    @FXML
    private ChoiceBox<KeyValue> typeQuery;
    @FXML
    private DatePicker dateQuery;
    @FXML
    private TableColumn<GetCardLoseOrChangeOutData, String> status;
    private ObservableList<GetCardLoseOrChangeOutData> tableList = FXCollections.observableArrayList(new ArrayList());
    @Autowired
    private IndexController indexController;

    public void initialize(URL location, ResourceBundle resources) {
        this.scrollPane.setPrefWidth(this.getContentWidth());
        this.scrollPane.setPrefHeight(this.getContentHeight());
        this.vBox.setPrefWidth(this.getContentWidth());
        this.vBox.setPrefHeight(this.getContentHeight());
        this.tableView.setPrefWidth(this.getContentWidth());
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        StringConverter converter = CommonUtil.dataPickerFormat("yyyyMMdd");
        this.dateQuery.setConverter(converter);
        ArrayList<KeyValue> option = new ArrayList<KeyValue>();
        option.add(new KeyValue("\u6302\u5931", "1"));
        option.add(new KeyValue("\u89e3\u6302", "2"));
        option.add(new KeyValue("\u6362\u5361", "3"));
        ObservableList options = FXCollections.observableArrayList(option);
        this.typeQuery.setItems(options);
        this.typeQuery.converterProperty().set(new StringConverter<KeyValue>(){

            public String toString(KeyValue object) {
                return object.getName();
            }

            public KeyValue fromString(String string) {
                return null;
            }
        });
        this.init();
    }

    @Override
    public void init() {
        this.indexController.scrollContentPane.setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

            public void handle(KeyEvent e) {
                if (e.getCode() == KeyCode.ENTER) {
                    CardLoseOrChangeQueryController.this.sureAction();
                }
                e.consume();
            }
        });
        this.dateQuery.setValue(null);
    }

    private TableView<GetCardLoseOrChangeOutData> initTableView() {
        GetCardLoseOrChangeInData inData = new GetCardLoseOrChangeInData();
        inData.setClientId(((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        inData.setName(this.nameQuery.getText().trim());
        inData.setNewCardNum(this.newCardNumQuery.getText().trim());
        if (ObjectUtil.isNotEmpty(this.typeQuery.getValue())) {
            inData.setType(((KeyValue)this.typeQuery.getValue()).getValue());
        }
        if (ObjectUtil.isNotEmpty(this.dateQuery.getValue())) {
            inData.setDate(DateUtil.format((Date)DateUtil.parse((String)((LocalDate)this.dateQuery.getValue()).toString()), (String)"yyyyMMdd"));
        }
        inData.setOldCardNum(this.oldCardNumQuery.getText().trim());
        inData.setPhone(this.phoneQuery.getText().trim());
        List<GetCardLoseOrChangeOutData> dataList = null;
        HttpJson httpJson = CardLoseOrChangeQueryUtil.queryTableList(CommonUtil.convertToMap(inData));
        if (httpJson.isSuccess()) {
            dataList = JSON.parseArray((String)httpJson.getMsg(), GetCardLoseOrChangeOutData.class);
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
        }
        this.tableList.clear();
        if (ObjectUtil.isNotEmpty(dataList)) {
            for (GetCardLoseOrChangeOutData data : dataList) {
                if ("1".equals(data.getStatus())) {
                    data.setStatus("\u6302\u5931");
                    continue;
                }
                if ("2".equals(data.getStatus())) {
                    data.setStatus("\u89e3\u6302");
                    continue;
                }
                data.setStatus("\u6362\u5361");
            }
            this.tableList = FXCollections.observableArrayList((Collection)dataList);
        }
        this.bingTableCell();
        this.tableView.setItems(this.tableList);
        return this.tableView;
    }

    private void bingTableCell() {
        this.date.setCellValueFactory((Callback)new PropertyValueFactory(this.date.getId()));
        this.shop.setCellValueFactory((Callback)new PropertyValueFactory(this.shop.getId()));
        this.cardName.setCellValueFactory((Callback)new PropertyValueFactory(this.cardName.getId()));
        this.index.setCellValueFactory((Callback)new PropertyValueFactory(this.index.getId()));
        this.oldCardId.setCellValueFactory((Callback)new PropertyValueFactory(this.oldCardId.getId()));
        this.newCardId.setCellValueFactory((Callback)new PropertyValueFactory(this.newCardId.getId()));
        this.sex.setCellValueFactory((Callback)new PropertyValueFactory(this.sex.getId()));
        this.voucherId.setCellValueFactory((Callback)new PropertyValueFactory(this.voucherId.getId()));
        this.time.setCellValueFactory((Callback)new PropertyValueFactory(this.time.getId()));
        this.user.setCellValueFactory((Callback)new PropertyValueFactory(this.user.getId()));
        this.status.setCellValueFactory((Callback)new PropertyValueFactory(this.status.getId()));
    }

    @FXML
    void sureAction() {
        if (ObjectUtil.isEmpty(this.dateQuery.getValue()) && ObjectUtil.isEmpty(this.newCardNumQuery.getText()) && ObjectUtil.isEmpty(this.oldCardNumQuery.getText()) && ObjectUtil.isEmpty(this.typeQuery.getValue()) && ObjectUtil.isEmpty(this.phoneQuery.getText()) && ObjectUtil.isEmpty(this.nameQuery.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5fc5\u987b\u81f3\u5c11\u586b\u5199\u4e00\u9879\u5185\u5bb9\u8fdb\u884c\u67e5\u8be2\uff01");
            alert.showAndWait();
            return;
        }
        this.initTableView();
    }

    @FXML
    private void reset() {
        this.nameQuery.clear();
        this.phoneQuery.clear();
        this.typeQuery.setValue(null);
        this.dateQuery.setValue(null);
        this.oldCardNumQuery.clear();
        this.newCardNumQuery.clear();
    }

    class KeyValue {
        private String name;
        private String value;

        public String getName() {
            return this.name;
        }

        public String getValue() {
            return this.value;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public boolean equals(Object o) {
            if (o == this) {
                return true;
            }
            if (!(o instanceof KeyValue)) {
                return false;
            }
            KeyValue other = (KeyValue)o;
            if (!other.canEqual(this)) {
                return false;
            }
            String this$name = this.getName();
            String other$name = other.getName();
            if (this$name == null ? other$name != null : !this$name.equals(other$name)) {
                return false;
            }
            String this$value = this.getValue();
            String other$value = other.getValue();
            return !(this$value == null ? other$value != null : !this$value.equals(other$value));
        }

        protected boolean canEqual(Object other) {
            return other instanceof KeyValue;
        }

        public int hashCode() {
            int PRIME = 59;
            int result = 1;
            String $name = this.getName();
            result = result * 59 + ($name == null ? 43 : $name.hashCode());
            String $value = this.getValue();
            result = result * 59 + ($value == null ? 43 : $value.hashCode());
            return result;
        }

        public String toString() {
            return "CardLoseOrChangeQueryController.KeyValue(name=" + this.getName() + ", value=" + this.getValue() + ")";
        }

        @ConstructorProperties(value={"name", "value"})
        public KeyValue(String name, String value) {
            this.name = name;
            this.value = value;
        }

        public KeyValue() {
        }
    }
}

